#include <my_header.h>

int main(int argc,char *argv[])
{
    //建立连接
    MYSQL* mysql=mysql_init(NULL);
    MYSQL* ret=mysql_real_connect(mysql,"localhost","root","123","OnlineStorage",0,NULL,0);
    if(ret==NULL)
    {
        fprintf(stderr,"%s:%s\n","mysql_real_connect",mysql_error(mysql));
        return -1;
    }

    char sql[500]={0};
 //   strcpy(sql,"create table vft (id int auto_increment,filename varchar(100),user varchar(50),parent_id int,md5 varchar(40),type varchar(10),path varchar(500),size varchar(200),primary key(id));");
 //   int qret=mysql_query(mysql,sql);
 //   if(qret!=0)
 //   {
 //       fprintf(stderr,"%s:%s\n","mysql_query",mysql_error(mysql));
 //       return -1;
 //   }
    bzero(sql,sizeof(sql));
    strcpy(sql,"insert into vft (filename,user,parent_id,type,path) values('/usr1','zhangsan','-1','d','/usr1');");
    mysql_query(mysql,sql);

    bzero(sql,sizeof(sql));
    strcpy(sql,"insert into vft (filename,user,parent_id,type,path,size) values('file1','zhangsan','1','f','/usr1/file1','123');");
    mysql_query(mysql,sql);

    bzero(sql,sizeof(sql));
    strcpy(sql,"insert into vft (filename,user,parent_id,type,path) values('dir1','zhangsan','1','d','/usr1/dir1');");
    mysql_query(mysql,sql);

    bzero(sql,sizeof(sql));
    strcpy(sql,"insert into vft (filename,user,parent_id,type,path) values('dir2','zhangsan','1','d','/usr1/dir2');");
    mysql_query(mysql,sql);

    bzero(sql,sizeof(sql));
    strcpy(sql,"insert into vft (filename,user,parent_id,type,path,size) values('file1','zhangsan','3','f','/usr1/dir1/file1','127');");
    mysql_query(mysql,sql);

    bzero(sql,sizeof(sql));
    strcpy(sql,"insert into vft (filename,user,parent_id,type,path) values('dir2','zhangsan','3','d','/usr1/dir1/dir2');");
    mysql_query(mysql,sql);

    bzero(sql,sizeof(sql));
    strcpy(sql,"insert into vft (filename,user,parent_id,type,path) values('dir3','zhangsan','3','d','/usr1/dir1/dir3');");
    mysql_query(mysql,sql);

    bzero(sql,sizeof(sql));
    strcpy(sql,"insert into vft (filename,user,parent_id,type,path) values('dir1','zhangsan','4','d','/usr1/dir2/dir1');");
    mysql_query(mysql,sql);

    bzero(sql,sizeof(sql));
    strcpy(sql,"insert into vft (filename,user,parent_id,type,path,size) values('file2','zhangsan','4','f','/usr1/dir2/file2','127');");
    mysql_query(mysql,sql);

//    char sql7[]="select * from vft;";
//    qret= mysql_query(mysql,sql7);
//    if(qret!=0)
//    {
//        fprintf(stderr,"%s:%s\n","mysql_query",mysql_error(mysql));
//        return -1;
//    }
//    MYSQL_RES* res=mysql_store_result(mysql);//取出结果，是行的集合
//    printf("row=%ld,col=%d\n",mysql_num_rows(res),mysql_num_fields(res));
//    for(unsigned i=0;i<mysql_num_rows(res);i++)
//    {
//        MYSQL_ROW row=mysql_fetch_row(res);
//        for(unsigned j=0;j<mysql_num_fields(res);++j)
//        {
//            printf("%s\t",row[j]);//任何类型的数据都转成了字符串
//        }
//        printf("\n");
//    }
//
//    for(int i=13;i<=30;i++)
//    {
//        char sql8[200]={0};
//        sprintf(sql8,"delete from vft where id=%d;",i);
//        int qret=mysql_query(mysql,sql8);
//        if(qret!=0)        
//        {                  
//            fprintf(stderr,"%s:%s\n","mysql_query",mysql_error(mysql));
//    /*         return -1; */       
//    /*     } */                  
//    /* } */
//
    mysql_close(mysql);
    return 0;
}

